﻿using NB.MGJ.Common.MVC;
using NB.MGJ.Model;
using NB.MGJ.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;


namespace NB.MGJ.Web
{
    public static class HtmlHelpers 
    {

        #region 下级机构下拉框  包括本机构



        /// <summary>
        /// 自定义下级机构下拉框
        /// </summary>
        /// <param name="eid">机构ID</param>
        /// <param name="strClass">样式class</param>
        /// <param name="name">name 和 ButtonId 属性</param>
        /// <returns></returns>
        public static MvcHtmlString Eselect (int EID, string strClass, string name)
        {
            TagBuilder tag = new TagBuilder("select");
            tag.MergeAttribute("class", strClass);
            tag.MergeAttribute("name", name);
            tag.MergeAttribute("id", name);
            ManagerService manager = new ManagerService();

            List<Organization_Enterprise> list = manager.GetSonEnterprise(EID);
            foreach (var item in list)
            {
                TagBuilder optionTtem = new TagBuilder("option");
                optionTtem.SetInnerText(item.EnterpriseName);
                optionTtem.MergeAttribute("value", item.ID.ToString());

                tag.InnerHtml += optionTtem.ToString();
            }
            return new MvcHtmlString(tag.ToString());
        }


        /// <summary>
        /// 自定义下级机构下拉框
        /// </summary>
        /// <param name="eid">机构ID</param>
        /// <param name="strClass">样式class</param>
        /// <param name="name">name 和 ButtonId 属性</param>
        /// <param name="valueChe">选中下拉框</param>
        /// <returns></returns>
        public static MvcHtmlString Eselect (int EID, string strClass, string name, int? valueChe)
        {
            TagBuilder tag = new TagBuilder("select");
            tag.MergeAttribute("class", strClass);
            tag.MergeAttribute("name", name);
            tag.MergeAttribute("id", name);
            ManagerService manager = new ManagerService();
            List<Organization_Enterprise> list = manager.GetSonEnterprise(EID);
            foreach (var item in list)
            {
                TagBuilder optionTtem = new TagBuilder("option");
                optionTtem.SetInnerText(item.EnterpriseName);
                optionTtem.MergeAttribute("value", item.ID.ToString());
                if (valueChe == item.ID)
                {
                    optionTtem.MergeAttribute("selected", "selected");
                }
                tag.InnerHtml += optionTtem.ToString();
            }
            return new MvcHtmlString(tag.ToString());
        }


        /// <summary>
        /// 自定义下级机构下拉框
        /// </summary>
        /// <param name="eid">机构ID</param>
        /// <param name="strClass">样式class</param>
        /// <param name="name">name  属性</param>
        /// <param name="valueChe">ButtonId 属性</param>
        /// <returns></returns>
        public static MvcHtmlString Eselect (int EID, string strClass, string name, string ID)
        {
            TagBuilder tag = new TagBuilder("select");
            tag.MergeAttribute("class", strClass);
            tag.MergeAttribute("name", name);
            tag.MergeAttribute("id", ID);
            ManagerService manager = new ManagerService();
            List<Organization_Enterprise> list = manager.GetSonEnterprise(EID);
            foreach (var item in list)
            {
                TagBuilder optionTtem = new TagBuilder("option");
                optionTtem.SetInnerText(item.EnterpriseName);
                optionTtem.MergeAttribute("value", item.ID.ToString());

                tag.InnerHtml += optionTtem.ToString();
            }
            return new MvcHtmlString(tag.ToString());
        }

        /// <summary>
        /// 自定义下级机构下拉框
        /// </summary>
        /// <param name="eid">机构ID</param>
        /// <param name="strClass">样式class</param>
        /// <param name="name">name  属性</param>
        /// <param name="valueChe">ButtonId 属性</param>
        /// <param name="valueChe">选中下拉框</param>
        /// <returns></returns>
        public static MvcHtmlString Eselect (int EID, string strClass, string name, string ID, int valueChe)
        {
            TagBuilder tag = new TagBuilder("select");
            tag.MergeAttribute("class", strClass);
            tag.MergeAttribute("name", name);
            tag.MergeAttribute("id", ID);
            ManagerService manager = new ManagerService();
            List<Organization_Enterprise> list = manager.GetSonEnterprise(EID);
            foreach (var item in list)
            {
                TagBuilder optionTtem = new TagBuilder("option");
                optionTtem.SetInnerText(item.EnterpriseName);
                optionTtem.MergeAttribute("value", item.ID.ToString());
                if (valueChe == item.ID)
                {
                    optionTtem.MergeAttribute("selected", "selected");
                }
                tag.InnerHtml += optionTtem.ToString();
            }
            return new MvcHtmlString(tag.ToString());
        }

        #endregion
    }
}
